{% extends "base.html" %}

{% block title %}用户注册 - 镜像传输系统{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-6 col-lg-5">
        <div class="card shadow">
            <div class="card-header bg-success text-white text-center">
                <h4 class="mb-0">
                    <i class="fas fa-user-plus me-2"></i>用户注册
                </h4>
            </div>
            <div class="card-body">
                {% with messages = get_flashed_messages(with_categories=true) %}
                    {% if messages %}
                        {% for category, message in messages %}
                            <div class="alert alert-{{ 'danger' if category == 'error' else category }} alert-dismissible fade show" role="alert">
                                <i class="fas fa-{{ 'exclamation-circle' if category == 'error' else 'info-circle' }} me-2"></i>
                                {{ message }}
                                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                            </div>
                        {% endfor %}
                    {% endif %}
                {% endwith %}

                <form method="POST" action="{{ url_for('auth.register') }}" id="registerForm">
                    <div class="mb-3">
                        <label for="username" class="form-label">
                            <i class="fas fa-user me-2"></i>用户名
                        </label>
                        <input type="text" class="form-control" id="username" name="username" 
                               placeholder="请输入用户名" required minlength="3" maxlength="20">
                        <div class="form-text">用户名长度3-20个字符，只能包含字母、数字和下划线</div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="email" class="form-label">
                            <i class="fas fa-envelope me-2"></i>邮箱
                        </label>
                        <input type="email" class="form-control" id="email" name="email" 
                               placeholder="请输入邮箱地址" required>
                        <div class="form-text">请输入有效的邮箱地址</div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="password" class="form-label">
                            <i class="fas fa-lock me-2"></i>密码
                        </label>
                        <input type="password" class="form-control" id="password" name="password" 
                               placeholder="请输入密码" required minlength="6">
                        <div class="form-text">密码长度至少6位，建议包含字母、数字和特殊字符</div>
                    </div>
                    
                    <div class="mb-3">
                        <label for="confirm_password" class="form-label">
                            <i class="fas fa-lock me-2"></i>确认密码
                        </label>
                        <input type="password" class="form-control" id="confirm_password" name="confirm_password" 
                               placeholder="请再次输入密码" required>
                        <div class="form-text">请再次输入密码以确保输入正确</div>
                    </div>
                    
                    <div class="mb-3 form-check">
                        <input type="checkbox" class="form-check-input" id="agree" name="agree" required>
                        <label class="form-check-label" for="agree">
                            我同意 <a href="#" data-bs-toggle="modal" data-bs-target="#termsModal">服务条款</a> 和 
                            <a href="#" data-bs-toggle="modal" data-bs-target="#privacyModal">隐私政策</a>
                        </label>
                    </div>
                    
                    <div class="d-grid">
                        <button type="submit" class="btn btn-success btn-lg">
                            <i class="fas fa-user-plus me-2"></i>立即注册
                        </button>
                    </div>
                </form>
                
                <hr class="my-4">
                
                <div class="text-center">
                    <p class="mb-2">已有账号？</p>
                    <a href="{{ url_for('auth.login') }}" class="btn btn-outline-primary">
                        <i class="fas fa-sign-in-alt me-2"></i>立即登录
                    </a>
                </div>
            </div>
        </div>
        
        <div class="text-center mt-3">
            <small class="text-muted">
                <i class="fas fa-shield-alt me-1"></i>
                注册即表示您同意我们的服务条款和隐私政策
            </small>
        </div>
    </div>
</div>

<!-- 服务条款模态框 -->
<div class="modal fade" id="termsModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">服务条款</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <h6>镜像传输系统服务条款</h6>
                <p>1. 本系统仅供合法用途使用</p>
                <p>2. 用户需遵守相关法律法规</p>
                <p>3. 禁止传输违法或侵权内容</p>
                <p>4. 系统管理员有权终止违规用户的服务</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 隐私政策模态框 -->
<div class="modal fade" id="privacyModal" tabindex="-1">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">隐私政策</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <h6>隐私保护政策</h6>
                <p>1. 我们保护用户的个人信息安全</p>
                <p>2. 不会向第三方泄露用户信息</p>
                <p>3. 用户数据仅用于系统功能</p>
                <p>4. 支持用户删除个人数据</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block extra_css %}
<style>
.card {
    border: none;
    border-radius: 15px;
}

.card-header {
    border-radius: 15px 15px 0 0 !important;
}

.form-control:focus {
    border-color: #198754;
    box-shadow: 0 0 0 0.2rem rgba(25, 135, 84, 0.25);
}

.btn-success {
    border-radius: 10px;
    padding: 12px;
}

.btn-outline-primary {
    border-radius: 10px;
}

.alert {
    border-radius: 10px;
}

.form-text {
    font-size: 0.875rem;
    color: #6c757d;
}
</style>
{% endblock %}

{% block extra_js %}
<script>
document.getElementById('registerForm').addEventListener('submit', function(e) {
    const password = document.getElementById('password').value;
    const confirmPassword = document.getElementById('confirm_password').value;
    
    if (password !== confirmPassword) {
        e.preventDefault();
        alert('两次输入的密码不一致！');
        return false;
    }
    
    if (password.length < 6) {
        e.preventDefault();
        alert('密码长度至少6位！');
        return false;
    }
    
    const username = document.getElementById('username').value;
    if (username.length < 3) {
        e.preventDefault();
        alert('用户名长度至少3位！');
        return false;
    }
    
    return true;
});

// 实时密码确认验证
document.getElementById('confirm_password').addEventListener('input', function() {
    const password = document.getElementById('password').value;
    const confirmPassword = this.value;
    
    if (confirmPassword && password !== confirmPassword) {
        this.setCustomValidity('密码不匹配');
    } else {
        this.setCustomValidity('');
    }
});
</script>
{% endblock %} 